package com.lfg.leetcode.leetcode0;

public class No88merge {

    public static void main(String[] args) {
        int[] nums1 = new int[]{1, 2, 3, 0, 0, 0};
        merge(nums1, 3, new int[]{2, 5, 6}, 3);
        for (int i : nums1) {
            System.out.println("[" + i + "]");
        }
    }

    public static void merge(int[] nums1, int m, int[] nums2, int n) {
        if (m + n > nums1.length) {
            return;
        }
        int i = 0;
        int j = 0;
        for (; i < m && j < n; i++) {
            if (nums1[i] > nums2[j]) {
                System.arraycopy(nums1, i, nums1, i + 1, m - i);
                nums1[i] = nums2[j];
                j++;
                m++;
            }
        }
        for (; i < nums1.length && j < n; ) {
            nums1[i++] = nums2[j++];
        }
    }

}

